﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using Wix.Aura.Common;
using System.IO;
using System.Xml.Serialization;
using System.Xml;
using Wix.Aura.Common.CustomTypes;
using System.Diagnostics;

namespace Wix.Aura.UnitTests.Common {
	[TestFixture]
	public class PackageAttributeSerialization : XmlAssertionBase {
		[SetUp]
		public void SetUp() {
			basexml =
@"<?xml version=""1.0"" encoding=""utf-8""?>
<Wix xmlns=""http://schemas.microsoft.com/Wix/2006/wi"">
	<Product Id=""00000000-0000-0000-0000-000000000000"" Language=""0"" Manufacturer=""manu"" Name=""name"" Version=""0.0.0.0"">
		{0}
	</Product>
</Wix>";

			testProject = CreateTestProject(new Package(Guid.Empty));
		}

		string basexml;
		WixProject testProject;

		private WixProject CreateTestProject(Package package) {
			return new WixProject(new Product(Guid.Empty, Language.Default, "manu", "name", "0.0.0.0", package));
		}

		[Test]
		public void TestIdParameter() {
			Guid id = Guid.NewGuid();
			WixProject project = CreateTestProject(new Package(id));
			string expected = string.Format(basexml, string.Format(@"<Package Id=""{0}"" />", id.ToString().ToUpper()));

			Assertion(expected, project);
		}

		[Test]
		public void SerializeAdminImageAttributeYes() {
			testProject.Product.Package.AdminImage = YesNoType.Yes;
			Assertion(string.Format(basexml, @"<Package Id=""00000000-0000-0000-0000-000000000000"" AdminImage=""yes"" />"), testProject);
		}

		[Test]
		public void SerializeAdminImageAttributeNo() {
			testProject.Product.Package.AdminImage = YesNoType.No;
			Assertion(string.Format(basexml, @"<Package Id=""00000000-0000-0000-0000-000000000000"" AdminImage=""no"" />"), testProject);
		}

		[Test]
		public void SerializeAdminImageAttributeComments() {
			string comment = "ThisIs AComment";
			testProject.Product.Package.Comments = comment;
			Assertion(string.Format(basexml, string.Format(@"<Package Id=""00000000-0000-0000-0000-000000000000"" Comments=""{0}"" />", comment)), testProject);
		}

		[Test]
		public void SerializeAdminImageAttributeComments2() {
			string comment = "ThisIs AnotherComment";
			testProject.Product.Package.Comments = comment;
			Assertion(string.Format(basexml, string.Format(@"<Package Id=""00000000-0000-0000-0000-000000000000"" Comments=""{0}"" />", comment)), testProject);
		}

		[Test]
		public void SerializeAdminImageAttributeCommentsEmpty() {
			string comment = string.Empty;
			testProject.Product.Package.Comments = comment;
			Assertion(string.Format(basexml, @"<Package Id=""00000000-0000-0000-0000-000000000000"" />"), testProject);
		}

	}
}